<template>
  <div>
    <MyReaderEcharts :option="option"></MyReaderEcharts>
  </div>
</template>

<script>
import MyReaderEcharts from "@/views/echarts/MyReaderEcharts";
export default {
  name: "ReaderEcharts",
  components: {MyReaderEcharts},
  data(){
    const colorList = [
      "#9f1fbd",
      "#42b8cc",
    ];

    return{
      option: {
        tooltip: {
          trigger: 'item'
        },

        title: {
          text: '用户分析',
          left: "center",
        },
        aria: {
          enabled: true
        },

        legend: {
          orient: 'vertical',
          x: 'right',
          type: "scroll",
          right: "5%",
          top: "13%",
          itemGap: 30,
          selectedMode: false,
          itemWidth: 50,
          itemHeight: 50,
          textStyle: {
            fontSize: 25,
          },
          icon: "pin",
        },
        color: colorList,
        series: [
          {
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: true,
            label: {
              show: false,
              position: 'center'
            },
            itemStyle: {

              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 4,
            },
            labelLine: {
              show: false
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '50',
                fontWeight: 'bold'
              }
            },

            data: [
              { value: 0, name: '管理员' },
              { value: 0, name: '用户' },
            ]
          }
        ]

      },
    }
  },
  mounted() {
    this.getData()
  },

  methods:{
    getData() {
      Promise.all([
        this.$axios.get('/admin/AdminCount'),
        this.$axios.get('/reader/ReaderCount')
      ])
          .then(([adminRes, readerRes]) => {
            const adminCount = adminRes.data.data.admincount;
            const readerCount = readerRes.data.data.readercount;
            this.option.series[0].data[0].value=[adminCount];
            this.option.series[0].data[1].value=[readerCount];
          });
    }
  }
}
</script>

<style scoped>

</style>